package com.example.demo.huawei;
// 数组按照元素个位数排序，个位数相同按照原有顺序排序

import java.util.*;

public class Main57 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.split(",");
        List<Integer> list = new ArrayList<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < split.length; i++) {
            int temp = Integer.parseInt(split[i]);
            map.put(temp, i);
            list.add(temp);
        }
        //19,-31,10,57,61,27,11,28,-94
        list.sort((o1, o2) -> {
            int a1 = Math.abs(o1);
            int a2 = Math.abs(o2);
            if (a2 % 10 == a1 % 10) {
                return map.get(o1) - map.get(o2);
            } else {
                return a1 % 10 - a2 % 10;
            }
        });
        for (int i = 0; i < list.size(); i++) {
            if (i == list.size() - 1) {
                System.out.print(list.get(i));
            } else {
                System.out.print(list.get(i) + ",");
            }
        }
    }
}
